PG-2512: Secure-erase sensitive data#39
Open
dutow wants to merge 1 commit into
Open
Conversation
Since the library deals with (private) keys and other possible secure data, we should make sure that everything we do uses a secure erase allocator. This is an API-breaking change since we have to modify the interface to use proper allocators.
jeltz
reviewed
Jul 14, 2026
jeltz
left a comment
There was a problem hiding this comment.
Not a full review, jsut took a quick look. One of the trickiest parts with reviewing this is making sure we have covered everything which may affect the public interfaces.
| ::memset_s(p, n, 0, n); | ||
| #elif defined(__GLIBC__) && \ | ||
| (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25)) | ||
| // glibc >= 2.25 and the BSDs provide explicit_bzero. |
There was a problem hiding this comment.
Comment is a bit funny as is is gated behind glibc only.
| } | ||
| // Compiler barrier so the writes are not reordered/coalesced away. | ||
| __asm__ __volatile__("" : : "r"(p) : "memory"); | ||
| #endif |
There was a problem hiding this comment.
Do we really need the fallback? glibc 2.25 was released in 2017. Does our C++ even compile on such ancient platforms?
| * dead-store elimination target: the optimizer sees the memory is never read | ||
| * again and removes the write, leaving secrets in place. secure_clear routes | ||
| * through a platform "explicit" zeroing primitive when available and falls | ||
| * back to a volatile write loop otherwise, so the store always happens. |
There was a problem hiding this comment.
I feel this comment is a bit unnecessary and can be shortened.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since the library deals with (private) keys and other possible secure data, we should make sure that everything we do uses a secure erase allocator.
This is an API-breaking change since we have to modify the interface to use proper allocators.